const https = require('https');
const cheerio = require('cheerio');

module.exports = function scrapeDataUrl(url, selector) {
    return new Promise((resolve, reject) => {
        https.get(url, (res) => {
            let data = '';
            res.on('data', (chunk) => {
                data += chunk;
            });
            res.on('end', () => {
                const $ = cheerio.load(data);
                const scrapedData = $(selector).map((i, el) => $(el).attr('href')).get();
                resolve(scrapedData);
            });
        }).on('error', (error) => {
            console.error(error);
            reject(error);
        });
    });
}
